import React from 'react';
import {View,Dimensions,ScrollView,Image} from 'react-native';
import SignatureCanvas from './SignatureCanvas';
import Button from '../../ant-copy/button/Button';

const {width,height} = Dimensions.get('window');

export default class SignatureDemo extends React.Component {
  state={
    img:null,
  }

  _setImg=()=>{
    this.refs.toImage().then(res=>{
      this.setState({
        img:res,
      })
      console.log(res);
    }).catch(err=>{
      console.log(err);
    });
  }

  render() {
    return (
      <View>
        <SignatureCanvas
          ref={(ref)=>this.refs = ref}
          width={width} height={200}/>
        <Button
          style={{ width: 50, marginLeft: 10 }}
          onClick={this._setImg}
        >
          截图
        </Button>
        {
          this.state.img&&<Image
            resizeMode='stretch'
            style={{width:width,height:200}}
            source={{uri:this.state.img}}
          />
        }
      </View>
    )

  }
}
